package com.sky.mapper;

import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderDetailMapper {
    @Insert("insert into order_detail " +
            "(order_id, dish_id, setmeal_id, dish_flavor, number, amount, name, image) " +
            "values " +
            "(#{orderId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{name},#{image})")
    void insert(OrderDetail orderDetail);

    @Select("select * from order_detail where order_id = #{id}")
    List<OrderDetail> findByOrderId(Long id);

    @Select("select od.* from order_detail od left join orders o on od.order_id = o.id where o.order_time > #{beginDateTime} and o.order_time < #{endDateTime} and o.status = 5")
    List<OrderDetail> findByOrderTime(LocalDateTime beginDateTime, LocalDateTime endDateTime);
}
